package cc.plumgo.ss.ui;

import javax.microedition.lcdui.Graphics;

import cc.plumgo.ss.ui.page.MenuPage;
import cc.plumgo.ss.ui.page.OverPage;
import cc.plumgo.ss.ui.page.PassPage;
import cc.plumgo.ss.ui.page.PausePage;
import cc.plumgo.ss.ui.page.PostPage;
import cc.plumgo.ss.ui.page.TextPage;
import cc.plumgo.ss.ui.text.MsgManager;

public class UIEngine {
	public static final int UI_HIDE = 0;
	public static final int UI_POST = 1;
	public static final int UI_MENU = 2;
	
	public static final int UI_HEAD = 3;
	public static final int UI_FOOT = 4;
	public static final int UI_PASS = 5;
	public static final int UI_OVER = 6;
	public static final int UI_PAUSE = 7;
	
	//public static final int UI_OPTION = ;
	
	//public static final int UI_START = 1;
	//public static final int UI_SWITCH = 3;
	public static final int UI_STATE_NUM = 8;
	
	private PostPage post;
	private MenuPage menu;
	
	private TextPage head;
	private TextPage foot;
	private PassPage pass;
	private OverPage over;
	private PausePage pause;
	
	//private ShowPage over;
	
	private int state = UI_HIDE;
	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public UIEngine() {
	}
	
	public void process(int keyStates, Graphics g) {
		switch (state) {
		case UI_POST : {
			if (post == null) {
				post = new PostPage();
				post.setState(PostPage.POST_SHOW);
			}
			post.process(keyStates, g);
			break;
		}
		case UI_MENU : {
			if (menu == null) {
				menu = new MenuPage();
				menu.setState(MenuPage.MENU_SHOW);
			}
			menu.process(keyStates, g);
			break;
		}
		case UI_HEAD : {
			if (head == null) {
				head = new TextPage(MsgManager.MSG_BACK);
				head.setState(TextPage.TEXT_SHOW);
			}
			head.process(keyStates, g);
			break;
		}
		case UI_FOOT : {
			if (foot == null) {
				foot = new TextPage(MsgManager.MSG_COMP);
				foot.setState(TextPage.TEXT_SHOW);
			}
			foot.process(keyStates, g);
			break;
		}
		case UI_PASS : {
			if (pass == null) {
				pass = new PassPage();
				pass.setState(PassPage.PASS_SHOW);
			}
			pass.process(keyStates, g);
			break;
		}
		case UI_OVER : {
			if (over == null) {
				over = new OverPage();
				over.setState(OverPage.OVER_SHOW);
			}
			over.process(keyStates, g);
			break;
		}
		case UI_PAUSE : {
			if (pause == null) {
				pause = new PausePage();
				pause.setState(PausePage.PAUSE_SHOW);
			}
			pause.process(keyStates, g);
		}
		}
	}
}
